package com.fc.authentication.modules.oauth.rs;

import com.fc.authentication.common.annotation.SysLog;
import com.fc.authentication.common.dto.Result;
import com.fc.authentication.common.validator.ValidatorUtils;
import com.fc.authentication.modules.oauth.service.AuthService;
import com.fc.authentication.modules.oauth.dto.AuthRequest;
import com.fc.authentication.modules.oauth.dto.AuthResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Sunny on 2018/6/21.
 */
@RestController
@RequestMapping("/api/oauth2")
@Api("登录验证接口")
public class OAuthResource {

    @Autowired
    private AuthService authService;

    @SysLog("用户登录")
    @ApiOperation("用户登陆")
    @PostMapping()
    public Result oauth2(@RequestBody AuthRequest authRequest)
    {
        ValidatorUtils.validateEntity(authRequest);
        AuthResponse response = authService.authentication(authRequest);
        return Result.ok(response);
    }
}
